# 作者：宋安康
# 开发时间：2023/6/27 12:28
import socket
import sys

# 服务端主机 IP 地址和端口号
HOST = '127.0.0.1'
PORT = 8000
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
    # 连接服务器
    s.connect((HOST, PORT))
except Exception as e:
    print( 'Server not found or not open ')
    sys.exit()

while True:
    c = input( 'Input the content you want to send: ')
    # 发送数据
    s.sendall(c.encode())
    # 从服务端接收数据
    data = s.recv(1024)
    data = data.decode()
    print( 'Received: ', data)
    if c.lower() == 'bye ':
       break
# 关闭连接
s.close()
